package com.sims.service.impl;

import com.sims.dao.ISimsStudentDao;
import java.util.List;
import com.sims.dao.impl.SimsStudentDaoImp;
import com.sims.eo.SimsStudent;
import com.sims.eo.StnUser;
import com.sims.service.IStudentService;

public class StudentServiceImp implements IStudentService {
	ISimsStudentDao simsStudentDao = new SimsStudentDaoImp();

	@Override
	public List<SimsStudent> getAllSimsStudent() {
		return simsStudentDao.getAllSimsStudent();
	}

	@Override
	public boolean deletSimsStudentById(Long id) {
		return simsStudentDao.deletSimsStudentById(id);
	}

	@Override
	public SimsStudent getSimsStudentById(Long id) {
		return simsStudentDao.getSimsStudentById(id);
	}

	@Override
	public boolean updateSimsStudent(SimsStudent student) {
		SimsStudent studentdb = getSimsStudentById(student.getId());
		int count = (int) simsStudentDao.getRowCountByStudentNumber(student
				.getStudentNumber());
		// 数据库不存在或者不是本条数据
		if (count < 1
				|| (count >=1 && student.getStudentNumber().equals(
						studentdb.getStudentNumber()))) {
			if (student.getStudentName() != null) {
				studentdb.setStudentName(student.getStudentName());
			}
			if (student.getStudentNumber() != null) {
				studentdb.setStudentNumber(student.getStudentNumber());
			}
			if (student.getSex() != null) {
				studentdb.setSex(student.getSex());
			}
			if (student.getHeight() != null) {
				studentdb.setHeight(student.getHeight());
			}
			if (student.getDepartment() != null) {
				studentdb.setDepartment(student.getDepartment());
			}
			if (student.getMajor() != null) {
				studentdb.setMajor(student.getMajor());
			}
			if (student.getQqNumber() != null) {
				studentdb.setQqNumber(student.getQqNumber());
			}
			if (student.getCellphone() != null) {
				studentdb.setCellphone(student.getCellphone());
			}
			return simsStudentDao.updateSimsStudent(studentdb);
		}

		return false;
	}

	@Override
	public List<SimsStudent> getAllSimsStudent(int pageNo, int pageSize) {
		return simsStudentDao.getAllSimsStudent(pageNo, pageSize);
	}

	@Override
	public long getRowCount() {
		return simsStudentDao.getRowCount();
	}

	@Override
	public long getRowCountByStudentNumber(String studentNumber) {
		return simsStudentDao.getRowCountByStudentNumber(studentNumber);
	}

	@Override
	public SimsStudent getStudentByStudentNumber(String studentNumber) {
		return simsStudentDao.getStudentByStudentNumber(studentNumber);
	}

	@Override
	public long createstudent(SimsStudent student) {
		long id = 0;
		int count = (int) simsStudentDao.getRowCountByStudentNumber(student
				.getStudentNumber());
		if (count < 1) {
			simsStudentDao.createstudent(student);
			id = student.getId();
		}
		return id;
	}

}
